#include "piped.hpp"
#include "log.hpp"


int main()
{
    Log log;
    //建立通信
    pipe_init init;

    int fd = open(FIFO_FILE,O_RDONLY);
    if(fd < 0){
        return FIFO_OPEN_ERR;
    }

    log(0,"string");
    log(1,"string");
    log(2,"string");
    log(3,"string");
    log(4,"string");

    
    while(true)
    {
        char buffer[SIZE] = {0};
        int n = read(fd,buffer,sizeof(buffer));
        if(n == -1){
            perror("read");
            exit(FIFO_READ_ERR);
        }
        else if(n > 0){
            buffer[n] = 0;
            //buffer[n] = '\n';
            std::cout << "PID :"<< getpid() << "cilent said # " << buffer <<std::endl;
        }
        else{
            break;
        }
    }

    close(fd);
    return 0;
}